# BeatStatistics/src/CMakeLists.txt - 管理源代码文件

# 获取所有头文件
file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/**/*.hpp")
file(GLOB_RECURSE SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/**/*.cpp")

# 确保 main.cpp 在列表中
list(APPEND SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp")

# 创建可执行文件
add_executable(${PROJECT_NAME} ${SRC_FILES} ${HEADERS})

# 添加选项，允许传入 IMPORTANALYSIS 路径，默认值为 "/home/lc/Documents/APP_Data/"
set(IMPORTANALYSIS_PATH "/home/lc/Documents/1215/中文/BeatEditor" CACHE STRING "Set the IMPORTANALYSIS path")

# 设置 IMPORTANALYSIS 变量，默认为指定的默认路径
set(IMPORTANALYSIS "${IMPORTANALYSIS_PATH}" CACHE STRING "Path for IMPORTANALYSIS")
# config
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h @ONLY)

# 设置链接语言
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)

# 设置可执行文件输出目录
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")

# 添加包含目录
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/src" ${CMAKE_BINARY_DIR})

# 查找 Qt库
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Concurrent Svg Charts)

# 查找 Threads 组件
find_package(Threads REQUIRED)

# 查找 TinyXML2
find_package(TinyXML2 REQUIRED)

# 查找 microcdr
find_package(microcdr REQUIRED)

# 查找 microxrcedds_client
find_package(microxrcedds_client REQUIRED)

# 查找 uuid 库（仅在非 Windows 平台上）
if(NOT WIN32)
    find_library(UUID_LIB uuid)
    if(NOT UUID_LIB)
        message(FATAL_ERROR "Could not find uuid library.")
    endif()
endif()


# 链接 Qt5 库和其他依赖库
if(WIN32)
    target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::Core Qt5::Concurrent Qt5::Svg Qt5::Charts Threads::Threads tinyxml2 microcdr microxrcedds_client Rpcrt4)
else()
    target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::Core Qt5::Concurrent Qt5::Svg Qt5::Charts Threads::Threads tinyxml2 microcdr microxrcedds_client ${UUID_LIB})
endif()
